local buyi = fk.CreateSkill {

  name = "joy__buyi",

  tags = {  },

}



buyi:addEffect(fk.EnterDying, {
  name = "joy__buyi",
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(buyi.name) and not target:isKongcheng() and player:usedSkillTimes(buyi.name, Player.HistoryTurn) <3
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, buyi.name, data, "#joy__buyi-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local id = room:askForCardChosen(player, target, "h", buyi.name)
    target:showCards({id})
    if Fk:getCardById(id).type == Card.TypeBasic and table.contains(target.player_cards[Player.Hand], id) then
      room:throwCard({id}, buyi.name, target, target)
      if target.dead or not target:isWounded() then return end
      room:recover{
        who = target,
        num = 1,
        recoverBy = player,
        skillName = buyi.name
      }
    end
  end,
})

return buyi